package com.ruoyi.interfaced.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.interfaced.domain.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.interfaced.service.IShopGoodsInterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品列表Controller
 * 
 * @author ruoyi
 * @date 2021-11-29
 */
@RestController
@RequestMapping("/interfaced/goods")
public class ShopGoodsInterController extends BaseController
{
    @Autowired
    private IShopGoodsInterService shopGoodsService;

    /**
     * 添加
     */

    @GetMapping("/select")
    public TableDataInfo select(ShopGoodsInter shopGoods)
    {
        startPage();
        List<ShopGoodsInter> list = shopGoodsService.select(shopGoods);
//        model.addAttribute(list);
//        System.out.println("list:"+list);
        return getDataTable(list);
    }

    /**
     * 添加
     */

    @GetMapping("/add")
    public String quan(ShopGoodsInter shopGoods)
    {
        int list = shopGoodsService.quan(shopGoods);
        System.out.println("list:"+list);
        return "成功";
    }

    /**
     * 修改
     */

    @GetMapping("/update")
    public String update(ShopGoodsInter shopGoods)
    {
        int list = shopGoodsService.update(shopGoods);
        System.out.println("list:"+list);
        return "修改成功";
    }

    /**
     * 修改
     */

    @GetMapping("/delete")
    public String delete(ShopGoodsInter shopGoods)
    {
        int list = shopGoodsService.delete(shopGoods);
        System.out.println("list:"+list);
        return "删除成功";
    }

    /**
     * shopuser
     */

    @GetMapping("/shopuser")
    public TableDataInfo listu()
    {
        List<ShopUserInter> list = shopGoodsService.shopuser();
        System.out.println("list:"+list);
        return getDataTable(list);
    }

    /**
     * 查询产品列表列表
     */
//    @PreAuthorize("@ss.hasPermi('order:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopGoodsInter shopGoods)
    {
        startPage();
        List<ShopGoodsInter> list = shopGoodsService.selectShopGoodsList(shopGoods);
        return getDataTable(list);
    }

    /**
     * shoppgoods
     */

//    @PreAuthorize("@ss.hasPermi('order:goods:commodity')")
    @GetMapping("/goods")
    public TableDataInfo listgs()
    {
        List<ShopGoodsInter> list = shopGoodsService.goods();
        System.out.println("list:"+list);
        return getDataTable(list);
    }

    /**
     * shopproperty
     */

//    @PreAuthorize("@ss.hasPermi('order:goods:commodity')")
    @GetMapping("/property")
    public TableDataInfo listp()
    {
        List<ShopProperty> list = shopGoodsService.property();
        System.out.println("list:"+list);
        return getDataTable(list);
    }

    /**
     * shoporderinfo
     */

//    @PreAuthorize("@ss.hasPermi('order:goods:commodity')")
    @GetMapping("/orderinfo")
    public TableDataInfo lists()
    {
        List<ShopOrderInfoInter> list = shopGoodsService.orderinfo();
        System.out.println("list:"+list);
        return getDataTable(list);
    }

    /**
     * 栏目显示
     */

//    @PreAuthorize("@ss.hasPermi('order:goods:commodity')")
    @GetMapping("/commodity")
    public TableDataInfo lista()
    {
        List<ShopCommodityInter> list = shopGoodsService.commodity();
        System.out.println("list:"+list);
        return getDataTable(list);
    }

    /**
     * 导出产品列表列表
     */
    @PreAuthorize("@ss.hasPermi('order:goods:export')")
    @Log(title = "产品列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopGoodsInter shopGoods)
    {
        List<ShopGoodsInter> list = shopGoodsService.selectShopGoodsList(shopGoods);
        ExcelUtil<ShopGoodsInter> util = new ExcelUtil<ShopGoodsInter>(ShopGoodsInter.class);
        util.exportExcel(response, list, "产品列表数据");
    }

    /**
     * 获取产品列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(shopGoodsService.selectShopGoodsById(id));
    }

    /**
     * 新增产品列表
     */
    @PreAuthorize("@ss.hasPermi('order:goods:add')")
    @Log(title = "产品列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopGoodsInter shopGoods)
    {
        return toAjax(shopGoodsService.insertShopGoods(shopGoods));
    }

    /**
     * 修改产品列表
     */
    @PreAuthorize("@ss.hasPermi('order:goods:edit')")
    @Log(title = "产品列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopGoodsInter shopGoods)
    {
        return toAjax(shopGoodsService.updateShopGoods(shopGoods));
    }

    /**
     * 删除产品列表
     */
    @PreAuthorize("@ss.hasPermi('order:goods:remove')")
    @Log(title = "产品列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(shopGoodsService.deleteShopGoodsByIds(ids));
    }
}
